//
//  VIPCollectionViewCell.m
//  intelligent
//
//  Created by 甘世清 on 2024/2/10.
//

#import "VIPCollectionViewCell.h"

@implementation VIPCollectionViewCell

- (instancetype)initWithFrame:(CGRect)frame{
    self = [super initWithFrame:frame];
    if (self) {
        self.layer.masksToBounds = YES;
        [self SQ_UIViewForSelfView];
    }
    return self;
}
/// 添加ui
-(void)SQ_UIViewForSelfView
{
    self.contentView.backgroundColor = UIColor.whiteColor;
    UIView * bgView = [[UIView alloc]init];
    bgView.backgroundColor = SQColor(@"#EEEEEE");
    bgView.layer.cornerRadius = 20;
    bgView.clipsToBounds = YES;
    bgView.layer.masksToBounds = YES;
    [self.contentView addSubview:bgView];
    [bgView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.edges.equalTo(self.contentView).insets(UIEdgeInsetsMake(16, 0, 16, 0));
    }];
    [self.contentView addSubview:self.bgImage];
    [self.bgImage mas_makeConstraints:^(MASConstraintMaker *make) {
            make.edges.equalTo(bgView);
    }];
    [self.contentView addSubview:self.topImage];
    [self.topImage mas_makeConstraints:^(MASConstraintMaker *make) {
            make.centerX.equalTo(self.contentView);
            make.top.equalTo(bgView).offset(-13);
            make.height.mas_equalTo(26);
            make.width.mas_equalTo(80);
    }];
    
    [self.contentView addSubview:self.label1];
    [self.label1 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.equalTo(self.contentView);
        make.top.equalTo(bgView).offset(23);
    }];
    [self.contentView addSubview:self.label2];
    [self.label2 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.equalTo(self.contentView);
        make.top.equalTo(bgView).offset(53);
    }];
    [self.contentView addSubview:self.label3];
    [self.label3 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.equalTo(self.contentView);
        make.top.equalTo(bgView).offset(97);
    }];
    [self.contentView addSubview:self.label4];
    [self.label4 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.contentView).offset(6);
        make.right.equalTo(self.contentView.mas_right).offset(-6);
        make.height.mas_equalTo(26);
        make.bottom.equalTo(self.contentView.mas_bottom).offset(-4);
    }];
}
- (void)setModel:(VModel *)model{
    _model = model;
    if (model.isseleted) {
        _bgImage.hidden = NO;
        self.label1.textColor = SQColor666666;
        self.label2.textColor = SQColor333333;
        self.label3.textColor = SQColor333333;
    } else {
        _bgImage.hidden = YES;
        self.label1.textColor = SQColor999999;
        self.label2.textColor = SQColor999999;
        self.label3.textColor = SQColor999999;
    }
    if (model.giveDiamond > 0) {
        self.label4.hidden = NO;
        self.label4.text = [NSString stringWithFormat:@"%@%d%@",SQNSLocalString(@"送"),model.giveDiamond,SQNSLocalString(@"积分")];
    } else {
        self.label4.hidden = YES;
    }
    self.topImage.hidden = !model.isOne;
    
    self.label1.text = model.name;
    self.label2.text =[NSString stringWithFormat:@"%@%@",model.prefix,model.price];
    self.label2.keywords = model.prefix;
    self.label2.keywordsFont = FONT_MEDIUM(14);
    [self.label2 getLableSizeWithMaxWidth:100];
    self.label3.text =[NSString stringWithFormat:@"%@%@",model.prefix,model.orgPrice];
    self.label3.deletelineStr = [NSString stringWithFormat:@"%@%@",model.prefix,model.orgPrice];
    [self.label3 getLableSizeWithMaxWidth:200];
}
- (HeaderView *)topImage{
    if (!_topImage) {
        _topImage = [[HeaderView alloc]init];
        _topImage.image = @"VipTop";
        _topImage.text = SQNSLocalString(@"限时优惠");
        _topImage.font = FONT_MEDIUM(13);
        _topImage.colorString = @"#FFFFFF";
    }
    return _topImage;
}
- (UIImageView *)bgImage{
    if (!_bgImage) {
        _bgImage = [[UIImageView alloc]init];
        _bgImage.image = SQGetImage(@"矩形备份 7");
        _bgImage.contentMode = UIViewContentModeScaleAspectFill;
        _bgImage.hidden = YES;
        _bgImage.layer.cornerRadius = 20;
        _bgImage.clipsToBounds = YES;
        _bgImage.layer.masksToBounds = YES;
    }
    return _bgImage;
}
- (UILabel *)label1{
    if (!_label1) {
        _label1 = [[UILabel alloc]init];
        _label1.font = FONT_REGULAR(16);
        _label1.textColor = SQColor333333;
        _label1.textAlignment = NSTextAlignmentCenter;
    }
    return _label1;
}
- (UILabel *)label2{
    if (!_label2) {
        _label2 = [[UILabel alloc]init];
        _label2.font = FONT_MEDIUM(28);
        _label2.textColor = SQColor333333;
        _label2.textAlignment = NSTextAlignmentCenter;
    }
    return _label2;
}
- (UILabel *)label3{
    if (!_label3) {
        _label3 = [[UILabel alloc]init];
        _label3.font = FONT_LIGHT(12);
        _label3.textColor = SQColor333333;
        _label3.textAlignment = NSTextAlignmentCenter;
    }
    return _label3;
}
- (UILabel *)label4{
    if (!_label4) {
        _label4 = [[UILabel alloc]init];
        _label4.font = FONT_REGULAR(13);
        _label4.textColor = UIColor.whiteColor;
        _label4.layer.cornerRadius = 13;
        _label4.layer.masksToBounds = YES;
        _label4.backgroundColor = SQColor333333;
        _label4.hidden = YES;
        _label4.textAlignment = NSTextAlignmentCenter;
    }
    return _label4;
}
@end
